"""
质量验评
"""
import pytest
from playwright.sync_api import  expect,Playwright
import allure
from Config.config import *
from Config.URL import *
from Config.Base import Base
from Config.AutoFlowEngine import autoflow

# 测试用例数据
case_data = [{'bdname':'大庄水厂、智慧谷工业园、龙港新区 应急供水工程（大庄水厂标段）','type':'01.01.土方开挖', 'tablename':'表1.1 土方开挖单元工程施工质量验收评定表','projectname':'1-1-2-1-1-2-1-1-1','projectid':'1-1-2-1-1-2-1-1-1','username':'jianli1'}]

@pytest.mark.业务系统
@pytest.mark.质量管理
@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright,case):
    bdname = case['bdname']
    type = case['type']
    tablename = case['tablename']
    projectname = case['projectname']
    projectid = case['projectid']
    username = case['username']

    # headless=False
    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login("jianli1", password_admin)
    page = SetupTeardown.page

    SetupTeardown.expect_login()
    page.goto(url + url_zhiliangyanping)
    page.wait_for_timeout(1500)

    SetupTeardown.select_bd(bdname)
    page.get_by_placeholder("请输入工程名称").fill(projectname)
    page.get_by_role("button", name=" 查询").click()
    page.wait_for_timeout(1000)

    if page.get_by_role("button", name="重置验评").is_visible():
        page.get_by_role("button", name="重置验评").click()
        page.get_by_role("button", name="确定").click()
        expect(page.get_by_role("alert")).to_contain_text("重置成功")
        page.wait_for_timeout(2000)
    page.get_by_role("row", name=projectid).get_by_role("button").click()
    page.get_by_placeholder("输入关键字进行过滤").fill(type)
    page.get_by_role("treeitem", name=type).locator("div").first.click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("操作成功")
    page.get_by_role("button", name="质量验评").click()
    page.wait_for_timeout(1000)


    if page.get_by_role("tab", name="施工自检").is_visible():
        page.get_by_role("tab", name="施工自检").click()
        if page.get_by_role("row", name=tablename).is_visible():
            page.get_by_role("row", name=tablename).get_by_role("button", name="填报").click()
            page.get_by_role("button", name="保存填报信息").click()
            page.get_by_role("row", name=tablename).get_by_role("button", name="发起验评").click()
            page.get_by_placeholder("请输入签署密码").fill(password_flow)
            page.get_by_role("button", name="确定").click()
            expect(page.get_by_role("alert")).to_contain_text("请求成功")
            page.wait_for_timeout(500)
            page = autoflow(SetupTeardown, tablename)


    if page.get_by_role("tab", name="监理平行检").is_visible():
        page.get_by_role("tab", name="监理平行检").click()
        if page.get_by_role("row", name=tablename).is_visible():
            page.get_by_role("row", name=tablename).get_by_role("button", name="填报").click()
            page.get_by_role("button", name="保存填报信息").click()
            page.get_by_role("row", name=tablename).get_by_role("button", name="发起验评").click()
            page.wait_for_timeout(1500)
            if page.get_by_placeholder("请输入签署密码").is_visible():
                page.get_by_placeholder("请输入签署密码").fill(password_flow)
                page.get_by_role("button", name="确定").click()
            expect(page.get_by_role("alert")).to_contain_text("请求成功")
            page.wait_for_timeout(1000)
            page = autoflow(SetupTeardown, tablename)

    if page.get_by_role("tab", name="验收评定").is_visible():
        page.get_by_role("tab", name="验收评定").click()
        if page.get_by_role("row", name=tablename).is_visible():
            page.get_by_role("row", name=tablename).get_by_role("button", name="填报").click()
            page.get_by_role("button", name="保存填报信息").click()
            page.get_by_placeholder("请输入签署密码").fill(password_flow)
            page.get_by_role("button", name="确定").click()
            expect(page.get_by_role("alert")).to_contain_text("请求成功")
            page.wait_for_timeout(500)
            page = autoflow(SetupTeardown, tablename)

    SetupTeardown.close()


